#pragma warning(disable:4786) #include #include #include #include #include #include #include #include #include #include using namespace std; #define MEM(a,b) memset(a,(b),sizeof(a)) #define MAX(a,b) ((a) > (b) ? (a) : (b)) #define MIN(a,b) ((a) < (b) ? (a) : (b)) #define MP merge_pair #define pb push_back #define inf 1000000001 #define maxn 100005 typedef vector vi; struct node { node *l,*r; int lo,hi; int fx,gx; node() {fx=-10000000;gx=0;} node(int x,int y,int v) {lo=x;hi=y;fx=v;gx=1;} void update() { if(l->fx>r->fx) fx=l->fx,gx=l->gx; else if(l->fxfx) fx=r->fx,gx=r->gx; else fx=l->fx,gx=l->gx+r->gx; } }; node *root[maxn],*dummy=new node(); vi E[maxn],D[maxn]; int U[maxn],V[maxn]; int L[maxn],S[maxn],C[maxn],P[maxn],n; node* build(int a,int b) { node *nnode = new node(a,b,V[a]-a); if(a==b) { nnode->l=nnode->r=dummy; return nnode; } int m=(a+b)/2; nnode->l = build(a,m); nnode->r = build(m+1,b); nnode->update(); return nnode; } node merge(node A,node B) { if(A.fx>B.fx) return A; if(B.fx>A.fx) return B; node C; C.fx=A.fx; C.gx=A.gx+B.gx; return C; } // query for the maximum value and the count of the max val node query(node *x,int a,int b) { int lo=x->lo,hi=x->hi; if(x==dummy || lo>b || hib) return *dummy; if(lo>=a && hi<=b) return *x; int m=(a+b)/2; node L=query(x->l,a,b); node R=query(x->r,a,b); return merge(L,R); } // update the segment tree corresponding to a chain void update(node *x,int a,int c) { int lo=x->lo,hi=x->hi; if(lo>a || hifx=c; x->gx=1; return ; } update(x->l,a,c); update(x->r,a,c); x->update(); } // heavy-light decomposition void bfs(int s) { int i,j,k; queue Q; MEM(L,-1); MEM(P,-1); Q.push(s); L[s]=1; while(!Q.empty()) { int u=Q.front();Q.pop(); D[L[u]].push_back(u); for(i=0;i=1;i--) { if(D[i].size()==0) continue; for(j=0;jmaxs) maxs=S[v],next=v; } if(next==-1) break; u=next; } root[x]=build(L[x],L[u]); } } } void modify(int u,int c) { update(root[C[u]],L[u],c-L[u]); return ; } node solve(int u) { node ret; while(1) { node tmp; if(C[u]==1) { tmp=query(root[C[u]],L[1],L[u]); ret=merge(tmp,ret); return ret; } else { tmp=query(root[C[u]],L[C[u]],L[u]); ret=merge(tmp,ret); u=P[C[u]]; } } return ret; } int main() { int i,j,k,q; scanf("%d%d",&n,&q); assert(n>=1 && n<=100000 && q>=1 && q<=300000); for(i=1;i<=n;i++) { scanf("%d",&U[i]); assert(U[i]>=1 && U[i]<=1000000000); } for(i=2;i<=n;i++) { int a; scanf("%d",&a); assert(a>=1 && a=0 && type<=1 && a>=1 && a<=n); if(type==0) { scanf("%d",&b); assert(b>=1 && b<=1000000000); modify(a,b); } else { node ret=solve(a); printf("%d %d\n",ret.fx+L[a],ret.gx); } } return 0; }